<?php
/**
 * App端 新闻管理
 * Author: lyun
 * Date: 2018/11/23
 * Created by Panxsoft.
 */


namespace App\Http\Controllers\Api\V1\App\Webview;

use App\Http\Controllers\ApiController;
use App\Http\Requests\App\PressIndexRequest;
use App\Http\Requests\App\PressRecommendProductsRequest;
use App\Http\Services\Api\V1\App\Webview\PressService;
use App\Models\Setting;
use App\Models\Store\Store;
use App\Services\MobileApp\AppEnv;
use Illuminate\Http\Request;

class PressController extends ApiController
{
    public $press_service;

    /**
     * PressController constructor.
     */
    public function __construct()
    {
        $this->press_service = new PressService;
    }

    /**
     * app端 新闻列表信息
     *
     * @param PressIndexRequest $request
     * @return array|\Illuminate\Http\Response
     */
    public function index(PressIndexRequest $request)
    {
        $presses = $this->press_service->getPressList($request);

        $app_theme = Setting::getSettingSpecifyValue('config_app_theme');

        return $this->response(compact('presses', 'app_theme'));
    }

    /**
     *  app端 新闻详情（包含增加阅读量和返回推荐商品）
     *
     * @param Request $request
     * @param $press_id
     * @return array|\Illuminate\Http\Response
     * @throws \Exception
     */
    public function show(Request $request, $press_id)
    {
        $store_id = AppEnv::storeId();

        $press_detail = $this->press_service->getPressDetail($press_id, $store_id);

        return $this->response($press_detail);
    }
}
